﻿using Microsoft.Phone.BackgroundTransfer;
using Q42.WinRT.Data;
using SpaceNeedle.SDK.Windows.Platform.Commands;
using SpaceNeedle.SDK.Windows.Platform.Data;
using SpaceNeedle.x6473.WindowsPhone.Common;
using SpaceNeedle.x6473.WindowsPhone.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SpaceNeedle.x6473.WindowsPhone.ViewModels
{
    public class UploadsViewModel : GlobalViewModel
    {
        public UploadsViewModel() :base()
        {

        }

        public AppContent.UploadsInfo StaticContent
        {
            get { return this.Get<AppContent.UploadsInfo>(); }
            set { this.Set(value); }
        }

        public string PageTitle
        {
            get { return this.Get<string>(); }
            set { this.Set(value); }
        }

        public List<BackgroundTransferRequestInfo> TransferRequestsInfo
        {
            get { return this.Get<List<BackgroundTransferRequestInfo>>(); }
            set { this.Set(value); }
        }

        public IEnumerable<BackgroundTransferRequest> TransferRequests
        {
            get { return this.Get<IEnumerable<BackgroundTransferRequest>>(); }

            set 
            { 
                if(value == null)
                {
                    return;
                }

                List<BackgroundTransferRequestInfo> transfers = new List<BackgroundTransferRequestInfo>();

                foreach (var item in value)
                {
                    transfers.Add(new BackgroundTransferRequestInfo(item));    
                }

                this.TransferRequestsInfo = transfers;

                this.Set(value);
            }
        }

        
        protected async override void Load()
        {
            this.IsInProgress = true;

            await base.LoadAsync();

            this.StaticContent = this.AppContent.Uploads;

            Tracking.SendView(ViewsNames.Uploads);

            this.IsInProgress = false;
        }
    }
}
